package com.itzyf.pokemondata.activity.illustration

import android.text.TextUtils
import android.view.View
import com.itzyf.pokemondata.R
import com.itzyf.pokemondata.bean.DbSkillDo
import com.itzyf.pokemondata.bean.DbSuperSkillDo
import com.tydic.baselibrary.activity.BaseActivity
import kotlinx.android.synthetic.main.activity_skill_detail.*
import org.litepal.LitePal
import org.litepal.extension.find

/**
 * @author 依风听雨
 * @version 创建时间：2019/06/04 12:30
 */
class SkillDetailActivity : BaseActivity() {
    override fun handlerActivity() {
        val id = intent.getLongExtra("id", -1L)
        if (id == -1L) {
            return
        }
        val type = intent.getIntExtra("type", -1)
        if (type == 0) {
            initSkill(LitePal.find<DbSkillDo>(id))
        } else if (type == 1) {
            initSuperSkill(LitePal.find<DbSuperSkillDo>(id))
        }
    }

    private fun initSuperSkill(superSkillDo: DbSuperSkillDo?) {
        superSkillDo?.let {
            setTitle(it.cname)
            tvTooltip.text = it.effect
            tvAttr.text = "类型：${it.property}"
            tvCType.text = "属性：${it.ctype}"
            tvPower.text = "威力：${it.power}"
            tvShoot.text = "命中：${it.hitRate}"

            llDetail.visibility = View.GONE
        }

    }

    private fun initSkill(skillDo: DbSkillDo?) {
        skillDo?.let {
            setTitle(it.cname)
            tvTooltip.text = it.tooltip
            tvAttr.text = "类型：${it.attribute}"
            tvCType.text = "属性：${it.ctype}"
            tvPower.text = "威力：${it.power}"
            tvShoot.text = "命中：${it.shooting}"
            tvPp.text = "次数：${it.pp}"

            if (TextUtils.isEmpty(it.detailed)) {
                llDetail.visibility = View.GONE
            } else {
                tvDetail.text = it.detailed
            }

        }

    }


    override fun getContentViewId() = R.layout.activity_skill_detail

    override fun getToolbarTitle() = ""

}